<template>
  <div class="app-container home">
    <el-row :gutter="20">
      <el-col :sm="24" :lg="12" style="padding-left: 20px">
        <h2>旅游后台管理</h2>
        <div id="Hot" style="width: 600px;height:400px;"></div>
      </el-col>

      <el-col :sm="24" :lg="12" style="padding-left: 50px;margin-top: 80px;">
        <div id="Sum" style="width: 600px;height:400px;"></div>
      </el-col>
    </el-row>
    <el-divider />
  </div>
</template>

<script>
import * as echarts from 'echarts';
import { getHomeHot,getHomeSum } from '../api/system/user';
export default {
  name: "Index",
  data() {
    return {
      // 版本号
      version: "3.8.9",
      echarts,
      HomeHot:[]
    };
  },
  created(){
    this.getHomeHot()
    this.getHomeSum()
    
  },  
  mounted() {
  },
  methods: {
    getHomeSum(){
      
      getHomeSum().then(res=>{
        console.log(res);
        this.HomeHot = res.data.map(item=>{
          return {
            value:item.sum,
            name:item.categoryName
          }
        })
        console.log(this.HomeHot);
        
    var myChart = echarts.init(document.getElementById('Sum'));
    console.log(myChart);
    
    // 指定图表的配置项和数据
    var option = {
      title: {
        text: '景点热度',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left',
      },
      series: [
        {
          name: '访问来源',
          type: 'pie',
          radius: [0, '70%'],
          center: ['50%', '50%'],
          roseType: 'area', // 设置roseType为'area'来生成玫瑰图
          itemStyle: {
            borderRadius: 8
          },
          data: this.HomeHot
        }
      ]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
      })
    },
    getHomeHot(){
      getHomeHot().then(res=>{
        console.log(res);
        this.HomeHot = res.data.map(item=>{
          return {
            value:item.views,
            name:item.attractionName
          }
        })
        console.log(this.HomeHot);
        
    var myChart = echarts.init(document.getElementById('Hot'));
    console.log(myChart);
    
    // 指定图表的配置项和数据
    var option = {
      title: {
        text: '景点热度',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left',
      },
      series: [
        {
          name: '访问来源',
          type: 'pie',
          radius: [0, '70%'],
          center: ['50%', '50%'],
          roseType: 'area', // 设置roseType为'area'来生成玫瑰图
          itemStyle: {
            borderRadius: 8
          },
          data: this.HomeHot
        }
      ]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
      })
    },
    goTarget(href) {
      window.open(href, "_blank");
    }
  }
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

